package logic

import (
	"context"
	"zero_demo06_rpc_api/user/rpc/dao"
	"zero_demo06_rpc_api/user/rpc/internal/svc"
	"zero_demo06_rpc_api/user/rpc/model"
	"zero_demo06_rpc_api/user/rpc/types/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserLogic {
	return &CreateUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateUserLogic) CreateUser(in *user.UserCreateRequest) (*user.UserCreateResponse, error) {
	// todo: add your logic here and delete this line

	if err := dao.Use(l.svcCtx.MySqlDb).UserEntity.Create(&model.UserEntity{
		Username: in.Username,
		Password: in.Password,
	}); err != nil {
		return &user.UserCreateResponse{
			Message: "创建失败",
		}, nil
	}
	return &user.UserCreateResponse{
		Message: "创建成功",
	}, nil
}
